package com.aurora.demo.api;

import com.aurora.demo.entity.Image;
import com.aurora.demo.service.ImageService;
import com.aurora.demo.util.Result;
import com.aurora.demo.util.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "1.图片相关接口")
@RequestMapping("/image")
@RestController
public class ImageController {

    @Autowired
    private ImageService imageService;

    @ApiOperation(value = "查询所有图片接口")
    @GetMapping("/findAll")
    public List<Image> findAll() {
        return imageService.findALl().subList(0,2);
    }

    @ApiModelProperty(value = "根据名字查找图片")
    @GetMapping("/find")
    public Result<Image> findByName(@RequestParam String name) {
        return ResultGenerator.genSuccessResult(imageService.findByName(name));
    }
}
